package Thread_case4_package;

import java.util.ArrayList;
import java.util.Collections;

public class MyThread extends Thread {
    //集合：{10,5,20,50,100,200,500,800,2,80,300,700}
    ArrayList<Integer> list;

    public MyThread(ArrayList<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {
        ArrayList<Integer> boxList = new ArrayList<>();
        while (true) {
            synchronized (Thread_case2_package.MyThread.class) {
                if (list.size() == 0) {
                    System.out.println(getName() + boxList);

                    break;
                } else {
                    //继续抽奖
                    Collections.shuffle(list);
                    Integer prize = list.remove(0);
                    //System.out.println(getName() + "又产生了一个" + prize + "元大奖");
                    boxList.add(prize);
                }
            }

            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
